@extends('manage.layout')

@section('content')
<body class="hold-transition skin-blue sidebar-mini">
  <!-- Content Wrapper. Contains page content -->
  <div class="content">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        添加角色&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/system/role" class="btn btn-primary">返回</a>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Role</a></li>
        <li class="active">Add Role</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- left column -->
        <div class="col-md-6">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title"></h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form  action="{{ url('system/role/addRole') }}"  role="form" method="post">

              {{ csrf_field() }}
              <div class="box-body" style="width: 50%;">
                <div class="form-group">
                  <label for="exampleInputEmail1">角色名称</label>
                  <input type="text" name="name" class="form-control" placeholder="role name" required="required">
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">权重</label>
                  <input type="number" name="rank" class="form-control" value="0" placeholder="role rank" required="required">
                </div>
              </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">提交</button>
              </div>
            </form>
          </div>
          <!-- /.box -->

        </div>
       
        <!--/.col (right) -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
@stop
@section('script')
  <script>
    $(function(){
      //提交表单
      $("form").submit(function(event) {
        event.preventDefault();
        var url = $(this).attr("action");
        $.ajaxSetup({
          headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
        });
        $.ajax({
          url: url,
          type: "POST",
          data: $("form").serialize(),
          dataType: "json",
          success: function(data) {
            console.log(data);
            if(data.error == 1) {
              window.location.href = "/system/role/addRole";
              layer.msg(data.msg,{icon: 1});
            }
            else {
              layer.msg(data.msg,{icon: 2});
            }
          }
        });
      });
    });

  </script>
@stop
